package com.lian.pet.domain.vo;

import com.lian.pet.common.basic.utils.DateUtil;
import com.lian.pet.domain.entity.Pets;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import org.springframework.util.ObjectUtils;

@AllArgsConstructor
@Data
@Builder
@ApiModel("查询宠物信息")
public class PetsVO {
    private Integer id;
    @ApiModelProperty(value = "宠物昵称")
    private String name;
    @ApiModelProperty(value = "宠物类别")
    private String breed;
    @ApiModelProperty(value = "宠物年龄（年）")
    private Integer ageYear;
    @ApiModelProperty(value = "宠物年龄（月）")
    private Integer ageMonth;
    @ApiModelProperty(value = "宠物体重")
    private Double weight;
    @ApiModelProperty(value = "宠物头像")
    private String photoUrl;
    @ApiModelProperty(value = "更新时间")
    private String updateTime;

    public static PetsVO fromPets(Pets entity, String urlPrefix) {
        return PetsVO.builder()
                .id(entity.getId())
                .name(entity.getName())
                .breed(entity.getBreed())
                .ageYear(entity.getAgeYear())
                .ageMonth(entity.getAgeMonth())
                .weight(entity.getWeight())
                .photoUrl(urlPrefix.concat(entity.getPhotoUrl()))
                .updateTime(ObjectUtils.isEmpty(entity.getUpdateTime())
                        ? DateUtil.dateToString(entity.getCreateTime())
                        : DateUtil.dateToString(entity.getUpdateTime()))
                .build();
    }
}
